package com.orange.core.pojo.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>ClassName:ERepairOrderEnum</p>
 * <p>Description: 维护单枚举类</p>
 * <p>Author: lwm</p>
 * <p>Date: 2025/5/29 0:07</p>
 */
@AllArgsConstructor
@Getter
public enum StatusEnum  implements Serializable {

    /**
     * 未处理
     */
    UNPROCESSED(0, "未处理"),

    /**
     * 处理中
     */
    PROCESSING(1, "处理中"),

    /**
     * 已处理
     */
    PROCESSED(2, "已处理");

    @EnumValue
    private final Integer code;
    @JsonValue
    private final String desc;

    private static final Map<Integer,StatusEnum> CODE_TO_MENUM_MAP = Arrays.stream(values())
//            .collect(Collectors.toMap(StatusEnum::getCode, e -> e));
            .collect(Collectors.toUnmodifiableMap(StatusEnum::getCode, e -> e));

    public static StatusEnum getByCode(Integer code) {
        StatusEnum statusEnum = CODE_TO_MENUM_MAP.get(code);
        if(statusEnum == null) {
            throw new IllegalArgumentException("无效的code值：" + code);
        }
        return statusEnum;
    }

}
